
//定义一个vue模块的映射表
import path from 'node:path'
import fs from 'node:fs'
const returnVuePath = (root) => {
    const node_modules = path.join(root, 'node_modules')
    let sfcPackagePath = path.join(node_modules, '@vue/compiler-sfc/package.json')
    let packageobj =JSON.parse(fs.readFileSync(sfcPackagePath, 'utf-8'))
    let module = packageobj.module
    packageobj.type = 'module'
    fs.writeFileSync(sfcPackagePath, JSON.stringify(packageobj))
    let complierSfc = path.join(path.dirname(sfcPackagePath), module)
    let resolvePath = (name) => {
        return path.join(node_modules, `@vue/${name}/dist/${name}.esm-bundler.js`)
    }
    let reactivity = resolvePath('reactivity')
    let runtimeCore = resolvePath('runtime-core')
    let shared = resolvePath('shared')
    let runtimeDom = resolvePath('runtime-dom')
    return {
        complierSfc,
        '@vue/runtime-core':runtimeCore,
        '@vue/reactivity':reactivity,
        '@vue/shared':shared,
        '@vue/runtime-dom':runtimeDom,
        'vue':runtimeDom
    }
}
export default returnVuePath